<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="left-panel"> </div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题 / 摘要" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="meetingId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="会议类型" prop="meetingTypeName" width="100"></el-table-column>
				<el-table-column label="会议主题" prop="subject" width="250" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="申请人" prop="createUserName" width="100"></el-table-column>
				<el-table-column label="会议室" prop="roomName" width="150"></el-table-column>
				<el-table-column label="预约状态" prop="sex" width="100">
					<template #default="scope">
						<el-tag v-if="scope.row.status=='0'">预约中</el-tag>
						<el-tag v-if="scope.row.status=='1'" type="success">预约成功</el-tag>
						<el-tag v-if="scope.row.status=='2'" type="warning">预约失败</el-tag>
						<el-tag v-if="scope.row.status=='3'" type="info">取消</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="会议主持" prop="chairUserName" width="150"></el-table-column>
				<el-table-column label="开始时间" prop="beginTime" width="150"></el-table-column>
				<el-table-column label="结束时间" prop="endTime" width="150"></el-table-column>
				<el-table-column label="联系电话" prop="tel" width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="210">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="approvalMeeting(scope.row, scope.$index)"  v-if="scope.row.status=='0'">审批</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<meeting-details v-if="dialog.save" ref="detailsDialog"  @closed="dialog.save=false"></meeting-details>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import MeetingDetails from "@/views/office/meeting/meetingDetails";
export default {
	name: 'Meeting Approval',
	components: {
		MeetingDetails,
		scSelectFilter
	},
	data() {
		return {
			dialog: {
				save: false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "会议类型",
					key: "meetingType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "审批状态",
					key: "status",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					},
						{
							value: '0',
							label: '预约中'
						},
						{
							value: '1',
							label: '预约成功'
						},
						{
							value: '2',
							label: '预约失败'
						},
						{
							value: '3',
							label: '会议取消'
						}
					],
				}
			],

			apiObj: this.$API.office.meeting.getApplyMeetingList,
			search: {
				date:'',
				meetingType:'',
				status:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getSysDicByCode();
	},
	methods: {
		async getSysDicByCode()
		{
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code:'meetingType'});
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.meetingType = data.meetingType;
			this.search.status = data.status;
			this.search.roomId = data.roomId;
			this.$refs.table.upData(this.search)
		},
		//编辑
		async approvalMeeting(row) {
			this.$confirm('请您按会议室的实际使用情况进行审批', '审批对话框', {
				distinguishCancelAndClose: true,
				confirmButtonText: '同意',
				cancelButtonText: '不同意'
			})
				.then(async () => {
					var reqData = {meetingId: row.meetingId,status:'1'}
					var res = await this.$API.office.meeting.updateMeeting.post(reqData);
					if (res.code == 200) {
						this.$refs.table.refresh()
						this.$message.success("审批成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}).catch(async action => {
					if(action === 'cancel')
					{
						var reqData = {meetingId: row.meetingId,status:'2'}
						var res = await this.$API.office.meeting.updateMeeting.post(reqData);
						if (res.code == 200) {
							this.$refs.table.refresh()
							this.$message.success("审批成功")
						} else {
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
		},
		//查看
		table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row);
			})
		},
		//删除
		async table_del(row) {
			var reqData = {meetingId: row.meetingId}
			var res = await this.$API.office.meeting.deleteMeeting.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style>
</style>
